package org.springblade.tms.global.enums;

import lombok.AllArgsConstructor;
import org.springblade.common.enums.Enumerator;
import org.springblade.tms.global.anno.SelectEnum;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author: wzq
 * @className: DemandStatusEnum
 * @createDate: 2022/3/9
 * @description: 需求单状态
 */
@AllArgsConstructor
@SelectEnum(value = "demandStatus", desc = "需求单状态枚举")
public enum DemandStatusEnum implements Enumerator {
	WAIT("wait", "待接单"),
	REJECTED("rejected", "已拒单"),
	ALREADY("already", "已接单"),
	TO_BE_LOADED("toBeLoaded", "待装货"),
	TO_BE_SHIPPED("toBeShipped", "待启运"),
	AWAITING_DELIVERY("awaitingDelivery", "待运达"),
	FINISH("finish", "已完成"),
	ABOLISHED("abolished", "已作废");

	private final String value;
	private final String description;

	@Override
	public String value() {
		return this.value;
	}

	@Override
	public String description() {
		return this.description;
	}

	/**
	 * 判断当前枚举和传入枚举的 是否属于  传入枚举-》当前枚举属于  顺序相邻关系
	 *
	 * @return
	 */
	public static boolean beforeCheck(DemandStatusEnum before, DemandStatusEnum after) {
		Arrays.stream(DemandStatusEnum.values()).collect(Collectors.toList());
		int beforeNum = -1;
		int afterNum = -1;

		boolean valid = false;

		for (int i = 0; i < values().length; i++) {
			if (before.equals(DemandStatusEnum.values()[i])) {
				beforeNum = i;
			}
			if (after.equals(DemandStatusEnum.values()[i])) {
				afterNum = i;
			}
			if (beforeNum != -1 && afterNum != -1) {
				valid = true;
				break;
			}
		}

		return valid && (afterNum - beforeNum == 1);
	}


	/**
	 * 判断当前枚举和传入枚举的 是否属于  传入枚举-》当前枚举属于  顺序相邻关系
	 *
	 * @return
	 */
	public static boolean beforeCheck(String before, String after) {
		Arrays.stream(DemandStatusEnum.values()).collect(Collectors.toList());
		int beforeNum = -1;
		int afterNum = -1;

		boolean valid = false;

		for (int i = 0; i < values().length; i++) {
			if (before.equals(DemandStatusEnum.values()[i].value)) {
				beforeNum = i;
			}
			if (after.equals(DemandStatusEnum.values()[i].value)) {
				afterNum = i;
			}
			if (beforeNum != -1 && afterNum != -1) {
				valid = true;
				break;
			}
		}

		return valid && (afterNum - beforeNum == 1);
	}
}
